package ysq.xyg.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import ysq.xyg.dao.ActivityDao;
import ysq.xyg.model.Activity;
import ysq.xyg.service.ActivityService;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author yu sheng qiang
 * @create 2017-03-22 15:37
 **/
@Service("activityService")
public class ActivityServiceImpl extends BaseServiceImpl<Activity> implements ActivityService {
    @Resource
    private ActivityDao activityDao;

    @Autowired
    public void setBaseDao(ActivityDao activityDao) {
        this.baseDao = activityDao;
    }

    @Override
    public PageInfo<Activity> pageInfo(Activity activity, int pageSize, int pageNum) {
        PageHelper.startPage(pageNum,pageSize);
        //通用Example查询
        PageHelper.orderBy(" start_time desc ");
        Example example = new Example(Activity.class);
        Example.Criteria criteria = example.createCriteria();
        if(StringUtil.isNotEmpty(activity.getPhone())){
            criteria.andLike("phone","%"+activity.getPhone()+"%");
        }
        if(StringUtil.isNotEmpty(activity.getAddress())){
            criteria.andLike("address","%"+activity.getAddress()+"%");
        }
        if(StringUtil.isNotEmpty(activity.getName())){
            criteria.andLike("name","%"+activity.getName()+"%");
        }

        List<Activity> list=activityDao.selectByExample(example);
        return new PageInfo<Activity>(list);
    }
    @Override
    public List<Activity> list(Activity activity) {
        //通用Example查询
        Example example = new Example(Activity.class);
        Example.Criteria criteria = example.createCriteria();

        if(StringUtil.isNotEmpty(activity.getPhone())){
            criteria.andLike("phone","%"+activity.getPhone()+"%");
        }
        if(StringUtil.isNotEmpty(activity.getAddress())){
            criteria.andLike("address","%"+activity.getAddress()+"%");
        }
        if(StringUtil.isNotEmpty(activity.getName())){
            criteria.andLike("name","%"+activity.getName()+"%");
        }
        example.setOrderByClause(" start_time desc ");
        List<Activity> list=activityDao.selectByExample(example);
        return list;
    }
}
